package cn.jslancer.service.impl;

import cn.jslancer.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.io.Serializable;

/**
 * @author jslancer
 * @date 2017/11/7
 */
public abstract class BaseServiceImpl<T, ID extends Serializable> implements BaseService<T, ID> {


    @Override
    public Iterable<T> findAll() {
        return getMongoRepository().findAll();
    }

    @Override
    public Iterable<T> findAll(Iterable<ID> ids) {
        return getMongoRepository().findAll(ids);
    }

    @Override
    public T save(T t) {
        return getMongoRepository().save(t);
    }

    @Override
    public Iterable<T> save(Iterable<T> ts) {
        return getMongoRepository().save(ts);
    }

    @Override
    public void delete(T t) {
        getMongoRepository().delete(t);
    }

    @Override
    public void delete(ID id) {
        getMongoRepository().delete(id);
    }

    @Override
    public T findOne(ID id) {
        return getMongoRepository().findOne(id);
    }

    @Override
    public Page<T> findAll(Pageable pageable) {
        return getMongoRepository().findAll(pageable);
    }

    @Override
    public boolean exists(ID id) {
        return getMongoRepository().exists(id);
    }

    @Override
    public long count() {
        return getMongoRepository().count();
    }

    @Override
    public Iterable<T> findAll(Sort sort) {
        return getMongoRepository().findAll(sort);
    }

    public abstract MongoRepository<T, ID> getMongoRepository();
}
